package com.my.ads.lib.receiver;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Build;
import android.support.v4.app.ActivityCompat;

import com.my.ads.lib.activity.MediaActivity;

/**
 * Created by xuanyang on 2018/3/6.
 */

public class VideoReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        try {
            String path = "";
            if (Build.VERSION.SDK_INT < 23 || ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                Cursor cursor = context.getContentResolver().query(intent.getData(),
                        null, null, null, null);
                cursor.moveToFirst();
                path = cursor.getString(cursor.getColumnIndex("_data"));
            }
            Intent tmp = new Intent(context, MediaActivity.class);
            tmp.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            tmp.putExtra("url", path);
            tmp.putExtra("type", 1);
            context.startActivity(tmp);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
